﻿///////////////////////////////////////////////////////////////////////////
//  Copyright(c) 2022, GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007
//
/// @file    hiobj.h
/// @brief   海思mpp相关结构体
/// @version 0.1
/// @history 修改历史
/// @warning 没有警告
///////////////////////////////////////////////////////////////////////////
#ifndef __HIOBJ_H__
#define __HIOBJ_H__


#include "klb_type.h"
#include "klua/klua.h"
#include "klbutil/CMap.hpp"

typedef struct hiobj_t_ hiobj_t;

typedef struct hiobj_reg_t_
{
    const char* p_name;
    int         size;

    int(*map2obj)(hiobj_t* p_dst, klb::CMap& src);
    int(*obj2map)(klb::CMap& dst, hiobj_t* p_src);
}hiobj_reg_t;


typedef struct hiobj_t_
{
    uint32_t    hash;
    hiobj_reg_t reg;

    char        data[];
}hiobj_t;


#define HIMPP_OBJ_HANDLE        "HIMPP_OBJ_HANDLE*"
#define to_hiobj(L, UD)         ((hiobj_t *)luaL_checkudata(L, UD, HIMPP_OBJ_HANDLE))


/// @brief  userdata
hiobj_t* new_hiobj(lua_State* L, const char* p_name);

typedef enum hiobj_mem_e_
{
    HIOBJ_mem1,
    HIOBJ_mem2,
    HIOBJ_mem3,
    HIOBJ_mem4,
    HIOBJ_mem5,
    HIOBJ_mem6,
    HIOBJ_mem7,
    HIOBJ_mem8,
    HIOBJ_mem_max,
}hiobj_mem_e;

/// @brief 临时缓存, 无需释放
hiobj_t* new_hiobj_mem(lua_State* L, int mem_idx, const char* p_name);

void checktype_hiobj(lua_State* L, hiobj_t* ptr, const char* p_name);

hiobj_t* lua_checkhiobj(lua_State* L, int arg, int mem_idx, const char* p_name);
void lua_pushhiobj_table(lua_State* L, hiobj_t* ptr);

void hiobj_mem_set(hiobj_t* ptr, lua_State *L, int idx);


#endif // __HIOBJ_H__
//end
